import { AppLogin } from './wptAppLogin';

// eslint-disable-next-line no-useless-escape
const weChatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i);
// eslint-disable-next-line no-useless-escape
const appInfo = navigator.userAgent.match(/WptMessenger\/([\d\.]+)/i);
const qrCodeLogin = !navigator.userAgent.match(/phone|android|ios|ipad/i);

let login;
let showLogin;

if (appInfo) {
    Object.assign(window.WPT, { login: AppLogin });
} else if (!qrCodeLogin && !weChatInfo && !appInfo) {
    login = (option, successCallback = () => {}) =>
        import('./wptWapLogin').then(({ login: wapLogin }) => wapLogin(option, successCallback));
    // eslint-disable-next-line max-len
    showLogin = (option) => import('./wptWapLogin').then(({ showLogin: wapShowLogin }) => wapShowLogin(option));
    Object.assign(window.WPT, { login, showLogin });
} else if (qrCodeLogin && !weChatInfo && !appInfo) {
    login = (option, successCallback = () => {}) =>
        import('./wptPCLogin').then(({ login: pcLogin }) => pcLogin(option, successCallback));
    Object.assign(window.WPT, { login });
} else if (weChatInfo) {
    //微信环境中
    Object.assign(window.WPT, {
        login() {
            WPT.Modal.alert('重新登录', () => {
                location.reload();
            });
        },
    });
}
